package cn.wwt.im.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.CoolItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.part.ViewPart;

import cn.wwt.im.core.Activator;

public class View extends ViewPart {
	public static final String ID = "cn.wwt.im.ui.view";
	StyledText text1,text2;
	Composite rootPanel;

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	public void createPartControl(Composite parent) {
		//this.form = new ViewForm(parent,SWT.NONE);
		//form.setLayout(new FillLayout());
		//text1 = new StyledText(form, SWT.MULTI | SWT.V_SCROLL);
		//form.setContent(text1);
		//text2 = new StyledText(form, SWT.MULTI | SWT.V_SCROLL);
		parent.setLayout(new FillLayout());
		rootPanel = new Composite(parent, SWT.NONE);
		FormLayout formLayout = new FormLayout();
		rootPanel.setLayout(formLayout);
		text1 =  new StyledText(rootPanel, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
		text2 =  new StyledText(rootPanel, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
		
		CoolBar coolbar = new CoolBar(rootPanel, SWT.NONE);
		ToolBar toolbar1 = new ToolBar(coolbar, SWT.NONE);
		//ToolBar toolbar2 = new ToolBar(rootPanel, SWT.NONE);
		ToolItem item1 = new ToolItem(toolbar1, SWT.PUSH);
		item1.setText("get");
		//item1.setImage(new Image(parent.getShell().getDisplay(), "res/alt_window_16.gif"));
		item1.setImage(new Image(parent.getShell().getDisplay(),Activator.getImageDescriptor("icons/alt_window_16.gif").getImageData()));
		ToolItem item2 = new ToolItem(toolbar1, SWT.PUSH);
		item2.setText("set");
		//item2.setImage(new Image(parent.getShell().getDisplay(), "res/alt_window_16.gif"));
		item2.setImage(new Image(parent.getShell().getDisplay(),Activator.getImageDescriptor("res/alt_window_16.gif").getImageData()));
		toolbar1.pack();
		CoolItem coolItem = new CoolItem(coolbar, SWT.NONE);
		coolItem.setControl(toolbar1);
		toolbar1.pack();
		Point point = new Point(toolbar1.getSize().x, toolbar1.getSize().y);
		coolItem.setSize(point);
		coolItem.setMinimumSize(point);
		
		FormData layoutData = new FormData();
		layoutData.top = new FormAttachment(70,0);
		layoutData.left =new FormAttachment(0,0);
		layoutData.bottom = new FormAttachment(100,0);
		layoutData.right = new FormAttachment(100,0);
		text2.setLayoutData(layoutData);	
		
		layoutData = new FormData();
		layoutData = new FormData();
		layoutData.top = new FormAttachment(0,0);
		layoutData.left =new FormAttachment(0,0);
		layoutData.bottom = new FormAttachment(coolbar,0,SWT.TOP);
		layoutData.right = new FormAttachment(100,0);
		text1.setLayoutData(layoutData);


		
		layoutData = new FormData();
		layoutData.bottom = new FormAttachment(text2,0,SWT.TOP);
		layoutData.left = new FormAttachment(0,0);
		layoutData.right = new FormAttachment(100,0);
		coolbar.setLayoutData(layoutData);
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		//form.setFocus();
	}
}